﻿using NHibernate;
using System.Web;
using System;

namespace HMIS.FrameWork.Repository.NHb
{
    public class HttpSessionStorage : ISessionStorage
    {
		[ThreadStatic]
		private static ISession m_Session;

        #region ISessionStorage 成员

        public NHibernate.ISession Get()
        {
			if (HttpContext.Current == null)
			{
				if (m_Session == null)
				{
					//System.Console.WriteLine("+++Open new Session....");
					m_Session = SessionBuilder.OpenSession();
				}
				return m_Session;
			}	
            return (ISession)HttpContext.Current.Items["NhbSession"];
        }

        public void Set(ISession value)
        {
            if (value != null)
            {
                HttpContext.Current.Items.Add("NhbSession", value);
            }
        }

        #endregion
    }
}
